/* 
 * File:   ArgumentParser.cpp
 * Author: brady
 * 
 * Created on August 26, 2011, 6:38 PM
 */

#include <parsing/ArgumentParser.h>

ArgumentParser::ArgumentParser() {
}

ArgumentParser::ArgumentParser(const ArgumentParser& orig) {
}

ArgumentParser::~ArgumentParser() {
}

RenderArgs ArgumentParser::parseArgs(int argc, char* argv[]) {
    
    stringstream dirss;
    RenderArgs args;
    
    //initialize defaults
    args.adaptiveMultiSampling = true;
    args.initialSamples = 1;
    args.maxSamples = 4;
    args.inputFile = "./src/scenes/scene1.xml";
    args.outputFile = "output.png";
    args.threadCount = 3;
    args.xResolution = 600;
    args.yResolution = 600;
    args.recursionLimit = 10;
    args.acceleration = "vg";
    
    dirss << argv[0];
    string rpath = dirss.str();

    struct option long_options[] = {
            {"adaptive",    0,  0, 'm'},
            {"samples",     1,  0, 's'},
            {"maxSamples",  1,  0, 'S'},
            {"input",       1,  0, 'i'},
            {"output",      1,  0, 'o'},
            {"threads",     1,  0, 't'},
            {"width",       1,  0, 'x'},
            {"height",      1,  0, 'y'},
            {"recursion",   1,  0, 'r'},
            {"focalLength", 1,  0, 'f'},
            {"photonMap"  , 1,  0, 'p'},
            {"acceleration",1,  0, 'a'},
            {0,0,0,0}
        };
    char* optString = "ms:S:i:o:t:x:y:r:f:p:a:?";
    int opt = 0;
    int longIndex = 0;
    opt = getopt_long( argc, argv, optString, long_options, &longIndex );
    while (opt != -1) {
        switch (opt) {
            case 'm':
            {
                args.adaptiveMultiSampling = true;
            }
                break;

            case 's':
            {
                args.initialSamples = atoi(optarg);
            }
                break;

            case 'S':
            {
                args.maxSamples = atoi(optarg);
            }
                break;

            case 'i':
            {
                stringstream ss;
                ss << optarg;
                args.inputFile = ss.str();
            }
                break;

            case 'o':
            {
                stringstream ss;
                ss << optarg;
                args.outputFile = ss.str();
            }
                break;
            case 't':
            {
                args.threadCount = atoi(optarg);
            }
                break;
            case 'x':
            {
                args.xResolution = atoi(optarg);
            }
                break;
            case 'y':
            {
                args.yResolution = atoi(optarg);
            }
                break;
            case 'r':
            {
                args.recursionLimit = atoi(optarg);
            }
                break;

            case 'a':
            {
                stringstream ss;
                ss << optarg;
                args.acceleration = ss.str();
            }
                break;

            default:
                /* You won't actually get here. */
                break;
        }

        opt = getopt_long(argc, argv, optString, long_options, &longIndex);
}
    return args;
}
